
package com.hehan.hhdemo.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.hehan.hhdemo.common.resp.ModelResp;
import com.hehan.hhdemo.common.resp.UserListResp;
import com.hehan.hhdemo.mapper.ModelMapper;
import com.hehan.hhdemo.mapper.UserMapper;
import com.hehan.hhdemo.po.User;
import com.hehan.hhdemo.service.IModelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hehan on 2018/10/24.
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private IModelService modelService;

    @Autowired
    private ModelMapper modelMapper;

    @GetMapping("/{userId}")
    @ApiOperation("查询单个用户")
    public User getUser(@PathVariable  Long userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    @GetMapping("/{pageNum}/{pageSize}")
    public Object listAll(@PathVariable Integer pageSize,@PathVariable Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        return userMapper.selectAll();
    }


    @GetMapping("/queryList")
    @ApiOperation("查询列表")
    public Map queryList(int pageSize, int pageNum) {
        Map map = new HashMap();
        PageHelper.startPage(pageNum,pageSize);
        List<ModelResp> list =  modelService.queryList();
        map.put("dataCount",modelMapper.selectCount(null));
        map.put("list",list);
        return map;
    }

}
